import { asyncRoutes, constantRoutes } from '@/router'

const state = {
  routes: []
}
const mutations = {
  setRoutes(state, route) {
    // 静态路由和动态路由拼接在一起，用于侧边栏显示
    state.routes = [...constantRoutes, ...route]
  }
}
// 筛选具有访问权限的路由对象
const actions = {
  // 筛选具有访问权限的路由对象
  filterRoutes(store, menus) {
    // menus
    // 所有动态路由 asyncRoutes
    // console.log(menus, asyncRoutes)
    const result = asyncRoutes.filter(item => {
      return menus.includes(item.name)
    })
    store.commit('setRoutes', result)
    return result
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
